from contextlib import contextmanager

import pymysql


@contextmanager
def cursor():
    # 打开数据库连接
    db = pymysql.connect("47.94.141.36", "root", "lx@123...", "test")
    cursor = db.cursor()

    try:
        yield cursor
    finally:
        db.close()
